﻿#pragma once
#pragma pack(push)
#pragma pack(1)


///////////////////////////////////////////////////////
#define ios_version
//comment this if you are using in Windows

///////////////////////////////////////////////////////
#define MSGVERSION '_FYW'
#define BUFFERSIZE 1024*10
///////////////////////////////////////////////////////
typedef enum
{
	hNull,
	hchLogin,				//1.客户端进入程序 进行登录验证
	hhcLoginSuccess,		//2.用户登录成功验证 返回当前用户信息
	hhcLoginFailure,		//3.登录失败
	hchGetRoomSort,			//4.客户端请求小盲注分类
	hhcSortedRoom,			//5.小盲注分类
	hchGetRoomList,			//6.客户端请求一种房间列表
	hhcRoomList,			//7.返回房间列表
	hchGetRoomInfo,			//8.客户端获取单一房间详细信息
	hhcRoomInfo,			//9.返回房间信息
	hchEnterRoom,			//10.进入房间
	hhcEnterRoomSuccess,	//11.进入成功
	hhcEnterRoomFailure,	//12.进入失败
	hchSitDown,				//13.坐下
	hhcSitDownSuccess,		//14.坐下成功
	hhcSitDownFailure,		//15.坐下失败
	hchStandUp,				//16.起身
	hhcStandUpSuccess,		//17.起身成功
	hhcStandUpFailure,		//18.起身失败
	

	hchGetGameInfo,			//19.获取游戏状态
	hhcReflashGameInfo,		//20.刷新游戏状态
	hchSetAutoAction,
	hchCommand,

	hMax
} client_server_enum;
/*****************************************************/
///////////////////////////////////////////////////////
//       Structures sent from CLIENT to SERVER       //
///////////////////////////////////////////////////////

//1.登录请求信息
///cmdId = hchLogin;
typedef struct
{
	char	usrName[33];		//用户登录名
	char	usrPWD[33];			//用户密码
	char	ClientType[8];		//客户端种类
	char	ClientVersion[8];	//客户端版本
}GetUsrInfo,*PGetUsrInfo;		//用户登录帐户信息
///////////////////////////////////////////////////////


//2.小盲注请求信息
///cmdId = hchGetRoomSort;
//non struct
///////////////////////////////////////////////////////


//3.房间列表请求信息
///cmdId = hchGetRoomList;
typedef struct
{
	int		smallblind;			
	int		maxPlayer;
	bool	isVip;
	bool	isFastSpeed;
	bool	isFull;				//isHoldHallRoom;???
}GetRoomList,*PGetRoomList;
///////////////////////////////////////////////////////

//4.单一房间请求信息
///cmdId = hchGetRoomInfo;
typedef struct
{
	int Id;
}	GetRoomInfo,EnterRoom;

//5.进入房间请求信息
///cmdId = hchEnterRoom;

//EnterRoom struct

///////////////////////////////////////////////////////

//6.坐下
///cmdId = hchSitDown;
typedef struct
{
	int roomId;
	int seatId;
	long long chips;
}SitDown;
///////////////////////////////////////////////////////

//6.用户动作
///cmdId = hchCommand;
 enum enum_AutoAction
 {
 auto_wait,
 auto_callany,
 auto_callnow,
 auto_foldany,
 auto_checkfold,
 auto_check,
 auto_allin
 
 };
 enum enum_Action
 {
 act_null,
 act_call,
 act_allin,
 act_raise, 
 act_fold,
 act_check,
 act_show
 };

typedef struct 
{
	int  butId;				//见前面枚举 enum_Action
	long long   butNum;				//筹码数
}ClientCommand,SetAutoCommand;


//cmdId = hchSetAutoAction;
//按钮代号 见前面枚举enum_AutoAction
//筹码数
/*****************************************************/

///////////////////////////////////////////////////////
//      Structures sent from SERVER to CLIENT        //
///////////////////////////////////////////////////////
typedef struct
{
	int itemCount;
	
}RoomUsrInfoCount,RoomSortInfoCount;
//1.登录返回信息
///cmdId = hhcLoginSuccess;
typedef struct
{
	int		usrID;				//用户ID
	char	usrNick[64];		//用户昵称
	int		usrExperience;		//用户经验
	int		usrCoins;			//用户金币
	long long	usrCounters;	//用户筹码
	char	usrInfo[256];		//额外信息json
}	UsrInfo,*PUsrInfo;			//登录验证返回的用户信息

///cmdId = hhcLoginFailure;
typedef struct
{
	short	errorCode;			//错误原因，0：账号密码错误，1:客户端版本过低.....		
}	LoginErrorInfo;				//登录失败，返回失败原因

///////////////////////////////////////////////////////

//2.小盲注返回信息
///cmdId = hhcSortedRoom;

//数量 = [socket readInt];
typedef struct
{
	long long smallblind;
}	RoomSortInfo,*PRoomSortInfo;
///////////////////////////////////////////////////////

//3.房间列表返回信息
///cmdId = hhcRoomList;

//数量 = [socket readInt];
typedef struct
{
	int		roomId;
	long long	smallblind;			//小盲
	long long	ante;				//底注
	int		maxPlayer;				//桌面几个人
	bool	isVip;					//是否是VIP
	bool	isFastSpeed;			//快速
	int		playerCount;			//当前玩家个数
}	RoomInfo,*PRoomInfo;
///////////////////////////////////////////////////////

//4.单一房间返回信息
///cmdId = hhcRoomInfo;

//数量 = [socket readInt];
typedef struct
{
	int			usrId;
	char		usrNick[65];		//用户昵称
	int			usrLevel;			//用户级别
	long long	usrCounters;		//用户筹码
	char		usrInfo[256];		//用户额外信息json
	int			position;			//用户所在桌面的位置
	int			HoleCards[2];			//用户手牌
}	RoomUsrInfo,*PRoomUsrInfo;	//当前房间用户玩家信息
///////////////////////////////////////////////////////

//5.进入房间返回信息
//cmdId = hhcEnterRoomSuccess;


 enum enum_GameStatus
 {
 s_waitGameStart,//=0************
 s_gameStart,//=1,
 s_dealHoleCards,//=2,
 s_waitPreFlop,//=3,**************
 s_procPreFlopAction,//=4,
 s_dealFlopCards,//=5,	
 s_waitFlopRound,//=6,************
 s_procFlopAction,//=7,
 s_dealTurnCards,//=8,
 s_waitTurnRound,//=9,************
 s_procTurnAction,//=10,
 s_dealRiverCards,//=11,
 s_waitRiverRound,//=12,**********
 s_procRiverAction,//=13,
 s_sendResult,//=14,
 s_gameEnd,//=15,
 s_waitReStart,//=16**************
 };


typedef struct
{
	short state;				//当前状态，见前面注释enum_GameStatus
	
	short turn;					//当前玩家
	short dealerSeat;			//D位置
	short smallBSeat;			//小盲注位置
	short bigBSeat;				//大盲注位置
	short boardCardsNum;		//公共牌数
	short boardCards[5];		//公共牌
	
	
	long long   money[9];				//玩家剩下的筹码数
	long long   stake[9];				//赌注(玩家当前轮所下的筹码数，即摆在玩家面前的筹码数)
	long long   lastStake[9];
	short potNum;				//彩池个数
	long long   pot[9];				//彩池
	
	bool  isPlaying[9];			//是否在玩
	bool  allin[9];				//是否全进
	char  lastCommand[9];		//玩家的动作 0Null 1post 2fold 3check 4bet 5call 6raise 7胜利
	long long   lastCommandChips[9];
	long long   lastMaxMoney;			//上一轮最大的注
	int   holeCards[2];			//用户手牌

	RoomUsrInfo rui[9];
}UpdateDesk,*PUpdateDesk;

//cmdId = hhcEnterRoomFailure;
typedef struct
{
	short	errorCode;
}EnterRoomErrorInfo;			//返回失败原因
///////////////////////////////////////////////////////

//6.坐下返回信息
//cmdId = hhcSitDownSuccess;

//返回单一房间返回信息

//cmdId = hhcSitDownFailure;
typedef struct
{
	short	errorCode;
}SitDownErrorInfo;

///////////////////////////////////////////////////////

#pragma pack(pop)
//typedef struct
//{
//	int roomId;
//}	EnterRoomSuccess;
///////////////////////////////////////////////////////
/*****************************************************/

/* ********************for the ios****************** */
#ifdef ios_version
#include <CoreGraphics/CGBase.h>
///////////////////////////////////////////////////////
typedef struct
{
	int msgVer;
	int msgLen;
	int cmdId;
}	MessageHeader;

CG_INLINE MessageHeader
NewHeader(int Ver,int Len,int Id)
{
	MessageHeader msg;
	msg.msgVer = Ver;
	msg.msgLen = Len;
	msg.cmdId = Id;
	return msg;
}
///////////////////////////////////////////////////////
CG_INLINE GetUsrInfo
NewAccount(NSData *userName,NSData *userPSW)
{
	GetUsrInfo ua;
	size_t userNameLen = [userName length]> sizeof(ua.usrName) -1?sizeof(ua.usrName) -1:[userName length];
	size_t userPSWLen = [userPSW length]> sizeof(ua.usrPWD) -1?sizeof(ua.usrPWD) -1:[userPSW length];
		
	memcpy(ua.usrName,[userName bytes],userNameLen);
	ua.usrName[userNameLen] = 0;
	
	memcpy(ua.usrPWD,[userPSW bytes],userPSWLen);
	ua.usrPWD[userPSWLen] = 0;
	
	//show result

	printf("usrName:%s\n",ua.usrName);
	printf("usrPSW:%s\n",ua.usrPWD);
	
	return ua;
}
///////////////////////////////////////////////////////
CG_INLINE UsrInfo
NewUsrInfo(PUsrInfo uip)
{
	UsrInfo ui;
//	memset(&ui,0,sizeof(UsrInfo));
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	memcpy(&ui,uip,sizeof(UsrInfo));
	
//	for (int i =0;  i<65; i++) {
//		printf("i:%d,%d\n",i,ui.usrNick[i]);
//	}
	
	return ui;
}
CG_INLINE int
SizeofUnichar(unichar * source)
{
	int i=0;
	for (; *(source+i); i++) {	
	}
	return i;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomSortInfo * sortedRoom;
	int num;

}	RoomSort,*PRoomSort;// for the client and not for the server
CG_INLINE RoomSort
NewRoomSort (RoomSortInfo * sorted,int num)
{
	RoomSort rs;
	rs.sortedRoom = sorted;
	rs.num = num;
	return rs;
}
///////////////////////////////////////////////////////

CG_INLINE RoomInfo
NewRoomInfo(PRoomInfo rip)
{
	RoomInfo ri;
	memcpy(&ri,rip,sizeof(RoomInfo));
	return ri;
}
///////////////////////////////////////////////////////
typedef struct
{
	RoomInfo * room;
	int num;
}	RoomList,PRoomList;
CG_INLINE RoomList
NewRoomList(PRoomInfo ri,int num)
{
	RoomList rl;
	rl.room = ri;
	rl.num = num;
	return rl;
}
CG_INLINE RoomList
NewRoomListNon()
{
	RoomList rl;
	rl.room = NULL;
	rl.num = 0;
	return rl;
}
///////////////////////////////////////////////////////
CG_INLINE UpdateDesk
NewUpdate(PUpdateDesk pud)
{
	UpdateDesk ud;
	memcpy(&ud,pud,sizeof(UpdateDesk));
	return ud;
	
}
///////////////////////////////////////////////////////
CG_INLINE UpdateDesk
NewUpdateNon()
{
	UpdateDesk ud;
	for (int i = 0; i < 9; i++) {
		ud.rui[i].usrId = -1;
		ud.turn = -1;
	}
	return ud;
}

///////////////////////////////////////////////////////
CG_INLINE SitDown
NewSitDown(int roomId,int seatId,long long chips)
{
	SitDown sd;
	sd.roomId = roomId;
	sd.seatId = seatId;
	sd.chips = chips;
	return sd;
}
///////////////////////////////////////////////////////
CG_INLINE ClientCommand
NewClientCommand(int btnID,long long btnNum)
{
	ClientCommand cc;
	cc.butId = btnID;
	cc.butNum = btnNum;
	return cc;
}
#endif
